/    Sign up×
Community /Pin to ProfileBookmark

Capture object values

The following js doesn’t work to capture the values in the “iframe” like object on my jspx page…

document.getElementById(“form1:object1”).document.forms(“Form2”).elements(“txtItem”).value

I’m using….

<div>
<object id=”object1″ name=”object1″ data=”https://www.site.com
type=”text/html” height=”500px” width=”500px”>
</object>
</div>

Can anyone help?

Thanks,
[tim]

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@toicontienSep 02.2008 — After [B]forms[/B] and [B]elements[/B], use square brackets instead of parenthesis.
Copy linkTweet thisAlerts:
@toicontienSep 02.2008 — Also, you cannot reference OBJECT elements using the FORM document object model. You need to give the <object> tag an Id and reference the OBJECT element using document.getElementById.
Copy linkTweet thisAlerts:
@_tim_authorSep 03.2008 — document.getElementById(form1:object1") is null

code:

document.getElementById("form1:object1").document.forms["Form2"].elements["txtItem"].value = "test";


...



<div>

<object id="object1" name="object1" data="https://www.site.com"

type="text/html" height="500px" width="500px">

</object>

</div>
Copy linkTweet thisAlerts:
@toicontienSep 03.2008 — There doesn't appear to be an HTML tag with "form1:object1" for an ID. In fact, that is an invalid Id.

What exactly are you trying to do? Are you embedding a web page using an OBJECT tag? Why not use an IFRAME and give the IFRAME a name? Then you could use:
window.frames.[I]IFRAME_NAME[/I].document.*
Given your code, you might be able to do:
document.getElementById("object1").document.*
And that will only work if both your web page and the webpage embedded in the OBJECT tag are from the same domain, otherwise you'll run into cross-site scripting security issues.
Copy linkTweet thisAlerts:
@_tim_authorSep 03.2008 — I am trying to embed a webpage within my page. I have discovered how to do this using an iframe. Complications arose while doing so, cross site scripting, that I had to overcome. This was a very difficult process. I read somewhere that cross site scripting would not be an issue if the page embedded within my page was inside of an object tag. If this is incorrect please let me know. Otherwise, I think that the approach is sound, if I could get the js syntax correct.

...

<div>

<object id="object1" name="object1" data="https://www.site.com"

type="text/html" height="500px" width="500px">

</object>

</div>

...

This code is wrapped in a form tag with an id of "form1".

Thanks,

[tim]
Copy linkTweet thisAlerts:
@BriDawgSep 03.2008 — I've been working on a similar case with what I think is the same issue. I tried with both brackets and parenthesis with no success. Has anyone figured out a solid solution for this??? :eek:

BriDawg
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — If the site in the iframe is another domain, you are not going to be able to touch it. Called security!

Eric
Copy linkTweet thisAlerts:
@_tim_authorSep 04.2008 — That's odd A1ien51, I've been able to do that very thing that you say I can't. Just trying to figure out how to do it with an object tag now.....?
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — If you are able to access form fields from "Google.com" from "example.com", than you need to check your browser settings. Being able to access another domain is scary because of what a person can do to your email, back accounts, etc.

Eric
Copy linkTweet thisAlerts:
@_tim_authorSep 04.2008 — I'm wrapping one webpage within my webpage. I then trick the embedded web page to think it's on my domain. Then I can use javascript within my page, and access anything I want on the embedded page. Works great with iframes, not so much with object tags, which is what I want to test, but I'm not sure how to access the elements within the object tag, like I can with the iframe. So if you can help me with that I'd really appreciate it.

Thanks,

[tim]
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — What is the code you use to "trick" the page with the iframe?

Eric
Copy linkTweet thisAlerts:
@_tim_authorSep 04.2008 — Government sensitive info. Please just help me with the js
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — Government sensitive info...lol...

If a government is using these poor hacks for bad coding I am scared.

If you are using something that allows you to access another domain, you really need to submit a bug to this browser company since it is a security flaw and not a real solution.

Eric
Copy linkTweet thisAlerts:
@_tim_authorSep 04.2008 — criticism isn't helping me at all. the point of the forum is to give me helpful suggestions. do you have any of those?
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — Reading/Interacting with data from another domain should not be possible. I would have tried to help you if I could figure out the "hack" you are doing. Since you can not share that information because of "Security" concerns with the government, than I can not help you out.

Eric
Copy linkTweet thisAlerts:
@_tim_authorSep 04.2008 — pretend the object tag is holding a page hosted on the same server. the js would be exactly the same either way. just looking for the syntax here.
Copy linkTweet thisAlerts:
@A1ien51Sep 04.2008 — <i>
</i>var myForm = document.getElementById("foo").contentDocument.forms[0];


Eric
×

Success!

Help @_tim_ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...