WomenInTech
WomenInTech

Reputation: 1141

set a defined user agent to an iFrame

Is it possible to set a defined user agent to an iFrame? If yes how?

Upvotes: 2

Views: 3155

Answers (2)

techfoobar
techfoobar

Reputation: 66663

This is not possible since the browsers have fixed user agent strings that they send with all request regardless of whether its from an iframe or not. And this is not something modifiable via JS.

You can however, have a script on your server which spoofs the user agent string (via curl for example) and then have your iframe call that script which in turn fetches the page you want called with a different user agent string and returns the output back to your iframe. For example: http://yourserver.com/yourproxy?url=<http://url-to-fetch/page>&ua=<user-agent-string-to-use>

Upvotes: 5

jfriend00
jfriend00

Reputation: 707446

No, this is not possible in a normal browser. The useragent that will be given to a server cannot be set via javascript. Some browsers allow you to mess with the useragent, but the only ones I've seen that allow that do it for all browser requests, not just for one particular iframe request.

Perhaps if you share the problem you're really trying to solve, we'd be more likely to be able to help.

Upvotes: 1

Related Questions