Forum Moderators: open

Message Too Old, No Replies

How to execute a remote javascript on a remote site?

Or am I wasting my time?

         

ronin

3:26 pm on Feb 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was hoping I'd be able to figure this out on my own, but I've been at it for hours and it's driving me crazy.

I would like to link to a dynamic page, which, as far as I can tell is only accessible by executing a javascript on a static html page (it then pulls all the elements together to create the dynamic page).

I would like to open the dynamic page in a new window, because it's an external resource, so I thought the best way to do this would be to open the static html page in a new window, then apply the javascript from that page onto the same window, thus leaving the reader looking at the dynamic document.

I know this would work theoretically, because I've tried just entering the javascript function alone into the address bar when I'm on the static html page and it brings up the dynamic page.

But how can I tell the browser to do this automatically?

So far I've tried linking to:

http://www.external.com/staticpage.html?javascript:newpage('id01');

okay, don't laugh, I knew this was a bit unlikely

and I've also tried using an onClick window.open javascript link for the [external.com...] (giving the window a name), followed by an onLoad event handler and trying to reload

javascript:newpage('id01');

into the address bar using the window name.

Nothing seems to work.

It doesn't seem like it ought to be that complex to open a new window and then, once that window has loaded, to enter a new url (or in this case bookmarklet) and refresh the window...?

hyperbole

8:07 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



You can't execute a javascript on another site from your page.

ronin

8:42 pm on Feb 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can I open a new window and then change the address in the new window and then refresh the window?

hyperbole

7:37 pm on Feb 23, 2004 (gmt 0)

10+ Year Member



If you open a new window and change the value of document.location it will automatically display the new location.

DrDoc

8:39 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't execute a javascript on another site from your page.

Sure you can... There are just limitations. The script on the other site can't access any of the elements on your page, but you can still use it to do basic things.

http://www.example.com/file.js

document.write("Hello World!");

Then in your document, just do:
<script src="http://www.example.com/file.js" type="text/javascript"></script>


Or...

http://www.example.com/file.js

function foobar(what) {
alert(what);
}

<script src="http://www.example.com/file.js" type="text/javascript"></script>
<script type="text/javascript">
foobar("this")
</script>

ronin

10:54 pm on Feb 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you open a new window and change the value of document.location it will automatically display the new location.

This is pretty much what I want to do. I'm going to explain this again, because I think I explained it badly the first time.

1) If I am on [othersite.com...] and I type into the address bar:

javascript: bookmarklet();

then the dynamic page that I would like to link to springs up.

2) This means that the javascript code is linked to from page1.html (though I can't find it, it's been buried away somewhere, or is external and the reference has been hidden) and it's on othersite.com.

3) So I would like to bring up a new window containing [othersite.com...] and then, once page1.html has finished loading, automatically rewrite the URL from my page (using javascript) as

javascript: bookmarklet();

4) I'm guessing this would have the (desired) identical effect as being on page1.html and entering

javascript: bookmarklet();

into the address bar.

Sorry for explaining myself badly.
The page is on the other site.
The javascript is on the other site.
The dynamic page is on the other site.

All I want to do is enter the URL, wait for the page to finish loading, change the content of the address bar and refresh the page.

Thanks.

GeorgeGG

12:26 am on Feb 24, 2004 (gmt 0)

10+ Year Member



hyperbold, like DrDoc said
you can still use it to do basic things

And using the src attribute you can send any JS client info to the same or
another server:

document.write("<script type=\"text/JavaScript\"
src=\"http*//www.example.com/cgi.js?A="+escape(document.referrer)+"\"></"+"script>");

You can add other JS variables as required, the cgi.js
is really a server script that can work on/log/whatever
is needed on the JS info received from the page.
Then the server can send back as a JS include file different page info,
JS variables etc as required or redirect to another page etc.

GGG

DrDoc

4:06 pm on Feb 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



4) I'm guessing this would have the (desired) identical effect as being on page1.html and entering
javascript: bookmarklet();
into the address bar.

I wouldn't bet a lot of money on that ;)
If anything, just calling the function bookmarklet() (as in one of my examples) should do it... And that's a much safer route.

ronin

12:48 am on Feb 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I see. Okay, thanks for that.
In that case, if rewriting the address bar would have no effect, I'm back to my original question...

Is it still possible call a remote .js function from my page and have it act upon a remote page contained in a child window?

The relevant .js script is contained within the body of the static .html document (I found it eventually)which makes it more tricky...

...but even if the .js script was externally referenced I have no idea of how to make it act upon a page on another site rather than a page on my site.

To boot there seems to be a cgi form which the javascript is acting on and I don't know how to reference the form either.

I think I'll just give up. I'm not sure the site, excellent resource though it is, deserves a link when they make it this complicated...

I think they're either super-paranoid about spiders or one of the underlying concepts of hyperlinking has utterly passed them by.

DrDoc

1:49 am on Feb 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it still possible call a remote .js function from my page and have it act upon a remote page contained in a child window?

I believe so. Just use the example I provided...