...

View Full Version : Open external URL in new window and run javascript



alchemist
11-13-2006, 01:43 PM
Hello everyone, this is my first post here on this forums....

I have a very straightforward question for you guys:

I would like to have a page on my site containing links to external URLs. When I click on these links, a new window should open with the new URL and some text formatting javascript (or other language) code be applied to it. This would be like loading a new URL and then run a bookmarklet to it. But I want to be able to do both in one shot. you click on the link, open a new window, and apply the code to the URL. Also, when you open the new window, the location bar should show the external URL, not mine. It doesn't have to necessarily be done with Javascript...if you know of other ways to attain this please advise.

thank you very much

VR2
11-13-2006, 01:52 PM
var win = window.open.....url, blah...

will give you a handle to the window you are opening. From there you can execute any javascript against that window.

eg: to append content to it (when loaded) you could do something like:

win.onreadystatechange = function()
{
if (win.readystate == 4)
{
var div = win.document.createElement("div");
div.innerHTML = "Hello other document world";
win.document.body.appendChild(div);
}

alchemist
11-13-2006, 02:08 PM
thank you for responding. ok...when you say "(when loaded)", you mean that after the new window has been loaded, I have to manually do something to cause the append javascript code to be executed?

alchemist
11-13-2006, 02:10 PM
let's use a real life example: I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?

VR2
11-14-2006, 05:02 PM
I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?

It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

VR2
11-14-2006, 05:02 PM
I want to open www.yahoo.com in a new window and replace all instances of "the" with an asterisk....would this be possible without opening the window first and then running a bookmarklet?

It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

Bill Posters
11-14-2006, 05:23 PM
It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

Bearing in mind that "the location bar should show the external URL, not mine", is the approach you have in mind still appropriate?


It sounds to me as though this is something which can only be achieved through taking advantage of some scripting on the external site, by which I mean, the admin of that site would need to set up their site to receive instructions or values which would then be used to adapt the content.
You'd need to set up an agreement or have some level of admin control over the destination site.

By reading the content of that site and displaying it 'in-house' (which is what I think VR2 is suggesting), you won't actually have the external site's url in the location bar because you won't actually be viewing that site, just scraping its content.

If it were possible to do what (I think) VR2 is suggesting and still have the external site's url in the location bar, that would be a major security hazard and would open the door to all sorts of malicious exploits such as phishing sites.

VR2
11-14-2006, 10:43 PM
the location bar should show the external URL, not mine

Ah yes, I forgot about that requirement - in that case then no, not really, you would fall foul of cross scripting.

Except for one idea.....

...what if the popup is not really a pop up, but a div, cleverly styled to look and act exactly like a window, complete with url bar - you could then display whatever url you liked in your fake window.

Or, more simply, have the popup show without a url bar (no longer possible in IE7 with default security).

Fake window it is then.

troth45
06-02-2012, 10:29 PM
It would be possible - most easily by using a server script to fetch & parse the document before it even reaches the browser.

Hi,
I'm such so curious to get an answer for this!
can you explain me how to fetch and parse the document before returning an output page?
Ex. In the server side I want to open yahoo.com, do something, then return the result to the client

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum