The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 20, 2019, 11:40:26 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Obtaining the contents of an external JS file clientside  (Read 3805 times)
cdc
Expert
****
Offline Offline

Posts: 105


View Profile
« on: March 29, 2008, 06:25:03 PM »

Sorry for the hiatus. VS pointed me to a thread here and I now realize what I've been missing all these months...

And here comes the first of many dumb questions!

Let's say that I have a page with the following code:

Code:
<script id="cdc" src="/myscript.js"></script>

I'd like to be able to access the contents of myscript.js on the client side. In other words, I'd like to do something like:

Code:
var thescript = document.getElementById('cdc').innerHTML;

Except innerHTML doesn't work because there isn't actually anything in the script tags.

Is there a way for me to access the contents of myscript.js?
« Last Edit: March 29, 2008, 06:38:41 PM by cdc » Logged

Will code for food.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: March 29, 2008, 10:59:13 PM »

Heh... a barely veiled hack my friend Wink

I have tried in vain to do that. Script is pulled down and loaded directly into the interpreter, not into the DOM, so you cannot get at it in a programmatic way. Is this a legit exercise that we can discuss different ways to go about something, or was it of darker origin...?
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
cdc
Expert
****
Offline Offline

Posts: 105


View Profile
« Reply #2 on: March 30, 2008, 04:35:48 AM »

darker, of course.  Devilish

But thanks for the answer. Now I won't waste any more time trying to get it to work.

Back to the drawing board.
Logged

Will code for food.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #3 on: March 30, 2008, 07:22:14 AM »

I can't imagine any reason why putting the javascript you require into xml format (may work with raw strings forgoing DOM style access but still putting the content into a var), then calling it with xmlhttprequest wouldnt work?

DM
Logged
cdc
Expert
****
Offline Offline

Posts: 105


View Profile
« Reply #4 on: March 30, 2008, 07:47:10 AM »

Unfortunately, I don't have control over the format of the JS that I'm calling.

I imagine it's the same story with iframes...no way to get the contents of what is brought back from the src attribute?
Logged

Will code for food.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: March 30, 2008, 11:53:24 AM »

That is correct, but iFrames are protected under a security context - so the data is on the DOM, you just can't get to it. You may find some success talking to JasonD, who has spent a good deal of time in this arena. No idea of his success, but it's right up his alley Wink
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!