PDA

View Full Version : I need help with SCR



ojsimon
11-16-2008, 10:01 AM
Hi
I am trying to run an external javascript that is on one of my other systems

When i view the source of the page the code i see is



<SCRIPT language="JavaScript">
document.write('<iframe width="400" height="200" allowtransparency="true" scrolling="no" frameborder="0" hspace="0" vspace="0" src="/websnips copy/index.php/widget/show/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156"></iframe>');
</SCRIPT>


I am trying to create a document like this

<script type="text/javascript" src="http://localhost:8888/websnips%20copy/index.php/widget/widget/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156"></script>


Which should embed the script above it, but it doesn't. Can anyone help me fix this problem?

Thanks

jscheuer1
11-16-2008, 02:05 PM
Is this all local (LAN)? I ask because that looks like a local path. Anyways, I'm having trouble following you. But there are two things we should get straight:


Why an iframe?
Are you trying to import a page or a script?


Oh, and just as a side note, don't use the deprecated language attribute in a script tag, and do use the required type attribute.

Now, if what you want to create with javascript is:



<script type="text/javascript" src="http://localhost:8888/websnips%20copy/index.php/widget/widget/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156"></script>

do:



<script type="text/javascript">
document.write('<script type="text/javascript" src="http://localhost:8888/websnips%20copy/index.php/widget/widget/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156"><\/script>');
</script>

ojsimon
11-16-2008, 02:16 PM
Thanks for your help. I am testing it on a local server yes, however it is for my website. Basically what i want is for my users to be able to embed this widget using an src however i was under the impression that i wouldn't be able to just src the file i want them to embed because it is html not js. Hence i used the iframe to make it javascript, and enable them to SRC it.

do you understand now?

Any advice?

Thanks

jscheuer1
11-16-2008, 02:28 PM
I get it a little better. If you want folks to embed something on their site, if it is a page, you can just tell them to put the iframe containing it directly into their code or you could have a script that writes out the tag for them.

ojsimon
11-16-2008, 02:31 PM
Is my way not possible? the problem is many people do not like iframes and also i find them quite buggy to work with. I have seen other sites that seem to be using the method i described.

Thanks

jscheuer1
11-16-2008, 02:40 PM
The trouble is I really don't understand what you are describing. Can you give me a link to a page that uses the method you want? And, could you try describing it better?

ojsimon
11-16-2008, 02:46 PM
Yeh sure one example is http://widgeteasy.com which lets the user generate a widget out of a feed.

1) The widget is constructed out of html,
See http://www.widgeteasy.com/rsswid.php?fid=201 (view source)


2) this page is then ifamed in javascript
http://www.widgeteasy.com/rss.v1.js

document.write('<iframe width="100%" height="312" allowtransparency="true" scrolling="no" frameborder="0" hspace="0" vspace="0" src="http://www.widgeteasy.com/rsswid.php?fid='+bunnywid.fid+'"></iframe>');

3) this js is then embedded into the site and given as an embed code using SCR
http://www.widgeteasy.com/widget.php?fid=201

<script type="text/javascript">bunnywid = { fid: 1108 };</script><script type="text/javascript" src="http://www.widgeteasy.com/rss.v1.js"></script>


Thanks for all your help.

jscheuer1
11-16-2008, 03:01 PM
Well this is all that is in that (http://www.widgeteasy.com/rss.v1.js) script:


document.write('<iframe width="100%" height="312" allowtransparency="true" scrolling="no" frameborder="0" hspace="0" vspace="0" src="http://www.widgeteasy.com/rsswid.php?fid='+bunnywid.fid+'"></iframe>');

So, you can do that sort of thing too. It requires that you have a page to serve, as the widget site does:

http://www.widgeteasy.com/rsswid.php

The customizing fid used by their server's PHP interpreter is passed via:


<script type="text/javascript">bunnywid = { fid: 201 };</script>

in that part of the code that is put on the user's page and picked up in their script with:


. . . teasy.com/rsswid.php?fid='+bunnywid.fid+'"></ifram . . .

ojsimon
11-16-2008, 03:07 PM
Hi
sorry i don't quite understand what you suggest i do?

Thanks

jscheuer1
11-16-2008, 03:23 PM
Do you have a page to serve? If so, use that here with its full path to its location on your server:


document.write('<iframe width="100%" height="312" allowtransparency="true" ' +
'scrolling="no" frameborder="0" hspace="0" vspace="0" ' +
'src="your page goes here"></iframe>');

Save that file as whatever.js and give your users the address to it to put on their page, ex:


<script src="http://full_path_on_your_server_to/whatever.js" type="text/javascript"></script>

Now, if your page (your page goes here) is a PHP page and you want your users to pass a code to it, you can have them use two scripts (like what the widget site does):


<script type="text/javascript">var myObject = { fid: 201 };</script>
<script src="http://full_path_on_your_server_to/whatever.js" type="text/javascript"></script>

Then in your whatever.js (add red):


document.write('<iframe width="100%" height="312" allowtransparency="true" ' +
'scrolling="no" frameborder="0" hspace="0" vspace="0" ' +
'src="your page goes here?fid=' + myObject.fid + '"></iframe>');

ojsimon
11-16-2008, 05:24 PM
Sorry to bother you again but the problem is i am using cake php, therefore the url endings cannot be .js i think this is the reason why it is still not running?

Is there anything else i can do to fix this?

Thanks

jscheuer1
11-16-2008, 05:35 PM
You may use whatever filename and extension you like for the javascript file, as long as the file itself contains the javascript code.

You could call it whatever.txt or whatever.php, or just whatever with no extension.

However, it seems absurd to me that there would be any type of PHP that would not allow you to use the .js extension, unless you have it set up wrong. But I'm not going to worry about that, my knowledge of PHP is just in passing. I don't do much work with it. So what you are saying could be the normal state of things in that type of PHP, I've never even heard of cake PHP.