aptx
aptx

Reputation: 73

Javascript in Blank Page Address Bar

javascript: alert();

This will work in a page already opened like 'http://example.com' but not from a blank page.

I have a code that want user to input 'e example' on the address bar using keyword search 'e' to execute JavaScript function 'abc(example)' like that

javascript: search='%s';if(window.location.host=='example.com'){abc(search);}else{window.location='http://example.com/'+search};

so if the current domain is example.com, then it will run some ajax function in the page to reduce server load, if not then it will simply go to a page on example.com.

The script works in

The script does not work in

it seem like in a blank page the window object is not even created so i can't set the url of it, any thought?

Upvotes: 3

Views: 619

Answers (1)

DG.
DG.

Reputation: 3517

You are correct. I've noticed the exact same thing for a very similar reason. That is just the way things are. Only way around is to create an extension/addon.

IIRC, bookmarklets will work in Chrome's about:blank, but to use about:blank as your default new tab requires an extension.

Upvotes: 2

Related Questions