Attache script to the visualforce parent page - javascript

I have added my visualforce page to Account page and found that I can set only fixed height. I wrote javascript solution for auto height. First part I added to the parentAccount page by adding new button with {!REQUIRESCRIPT("my_scipt_here")}, second part I added to visualforce page.
s it possible to add javascipt to the "parent" Account page without adding Custom Button?

I'm not aware of any way to run javascript on a page other than by using a button (or maybe a link as a field), though it'd be good to know if there is one but I highly doubt it would be available, or if it is, supported.
Would overriding the Account view page with a full visualforce page be an option where you use an <apex:detail> tag to get the standard fields etc.?

Remember that Visualforce components on page layouts occur as iframes. If the domains match up, which may or may not be the case - you could inject JavaScript from the iframe to the parent.
This may give more details:
Inject javascript function into parent window from iframe

Related

Moving an HTML+javascript page to iFrame

I have an existing website composed of individual pages (each page is a different tool that requires some user input (ie forms), and each with it's own set of javascript functions to populate dropdown lists, etc on that page). Each of the tools is accessed from the main index.html.
Instead of each tool being its own "stand-alone" page that is invoked from index.html, I'd like each tool to be displayed in an iFrame instead on the main page. This way the main page remains static, while only updating the iframe with whatever tool the user selects. So say on the main index page, I have a 3 tools menu (collect logs, collect KPIs, collect status), along with an iFrame. If the user selects collect logs for example, the menu containing "collect logs" stays there, but the "collect logs" page is displayed in the iFrame.
My problem is that all the HTML content works fine, but none of the javascript code in the selected tool page works (ie none of the drop downs get populated since it's the javascript code in the page that does that by reading a file on the server).
Is there an easy way to port each tool page (html+javascript) to an iFrame without having to re-write tons of code (in my naivety I thought simply invoking the page inside an iFrame using target='' in the href would work)? Or is there a better method of accomplishing what I'm trying to do? Maybe iFrame isn't the solution.
Content in iframes remain autonomous from the wrapper app, so it makes sense that it's not working correctly. Other than building a listener for a click event associated with the div wrapped around the iframe, the iframe document isn't accessible if it points to a different origin. (See [same-origin policy]
(https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy))
To stay with simple html/css/js solution:
You can use a regular div to wrap each 'stand-alone' content and then just use whatever button/navigation target you have display that div and hide the previous by changing their css display style with the onClick event.
More invasive option:
You may want to consider using a more modular JS approach, like React JS, to build components vs pages and utilize React's structure to toggle components.
With react you can render each 'tool' when the user selects it . You would be able to utilize React component state as well to help in storing data and such for the life-cycle of the component.

Determine which link (on same page) was used?

I have a page with two links to an introduction/registration page. We want to show different content based on which link the user uses. They appear in different contexts on the same page, and we would like to tailor the message on the registration page to that context. For SEO purposes I was told not to change the URL.
I'm using rails. Since the incoming user will have the same referrer regardless of which link was clicked, what is the best way to know which link was used to get to my page? Is it possible in a practical way without altering the URL?
I would change the href on click like described in How to change href of <a> tag on button click through javascript
But I would not change the whole url. I would only append a parameter. This should not influence SEO.

Single Page MVC Navigation

I am building a single page scrolling MVC website that needs to be able to move to different sections of the page when a link is clicked, preferably without refreshing the page, just scrolling to said location on click event. My question is whether this would be some JavaScript or whether I can do so with just some regular and some C#.
As Alexei Darmin said in a comment try to use #id's in divs and refer to those id's in your links, that's the tipical way to do it and you shouldn't have any problem unless you load the content dinamically, in that case you should implement a method in your angular control that force the async load to, at least, that point and move the user to it.
For single Page application, Angular Js is more efficient and you can achieve the performance also. And also if you use this script, your app is like Web Api,you can control your resolutions for different devices.
Angular Js is best , so you can use in your app. hope it will useful to you. Thanks.
just refer its useful to you :
Link1
Link2

What is alternatives to use popup to avoid Firefox4 popup maximum count?

I used to use Firefox3.6 but with Firefox4.0 when certain amount of popoup windows are generated, following message will appear.
Prevent this page from creating additional dialogs
According to my research, about:config page has dom.popup_maximum variable to adjust max popup limit but I cannot ask my end users to change their browser setting just because of my app.
I searched alternative coding to popup.
Many of them defines div and hide/show them with CSS using jQuery.
But I have 10 HTML pages with button that popup same page.
window.open("http://www.sample.com","samplePage");
I do not want to pre-define the contents of samplePage in every 10 pages for this reason.
Is there any alternative to popup which I do not have to pre-define in every page?
You can still do the css trick, but put an iframe in the div.
Click button then does the following:
1. Set iframe src attribute
2. Show hidden div
You can load that sample page dynamically. You either may use frames (especially <iframe>s in here) or any type of ayax, which means receiving data from the server (html, xml, json, whatever) and then showing the data in a <div>. You don't need jQuery for that.

How to display a form in any site's pages using a bookmarklet (like Note in Google Reader)?

In Google Reader, you can use a bookmarklet to "note" a page you're visiting. When you press the bookmarklet, a little Google form is displayed on top of the current page. In the form you can enter a description, etc. When you press Submit, the form submits itself without leaving the page, and then the form disappears. All in all, a very smooth experience.
I obviously tried to take a look at how it's done, but the most interesting parts are minified and unreadable. So...
Any ideas on how to implement something like this (on the browser side)? What issues are there? Existing blog posts describing this?
Aupajo has it right. I will, however, point you towards a bookmarklet framework I worked up for our site (www.iminta.com).
The bookmarklet itself reads as follows:
javascript:void((function(){
var e=document.createElement('script');
e.setAttribute('type','text/javascript');
e.setAttribute('src','http://www.iminta.com/javascripts/new_bookmarklet.js?noCache='+new%20Date().getTime());
document.body.appendChild(e)
})())
This just injects a new script into the document that includes this file:
http://www.iminta.com/javascripts/new_bookmarklet.js
It's important to note that the bookmarklet creates an iframe, positions it, and adds events to the document to allow the user to do things like hit escape (to close the window) or to scroll (so it stays visible). It also hides elements that don't play well with z-positioning (flash, for example). Finally, it facilitates communicating across to the javascript that is running within the iframe. In this way, you can have a close button in the iframe that tells the parent document to remove the iframe. This kind of cross-domain stuff is a bit hacky, but it's the only way (I've seen) to do it.
Not for the feint of heart; if you're not good at JavaScript, prepare to struggle.
At it's very basic level it will be using createElement to create the elements to insert into the page and appendChild or insertBefore to insert them into the page.
You can use a simple bookmarklet to add a <script> tag which loads an external JavaScript file that can push the necessary elements to the DOM and present a modal window to the user. The form is submitted via an AJAX request, it's processed server-side, and returns with success or a list of errors the user needs to correct.
So the bookmarklet would look like:
javascript:code-to-add-script-tag-and-init-the-script;
The external script would include:
The ability to add an element to the DOM
The ability to update innerHTML of that element to be the markup you want to display for the user
Handling for the AJAX form processing
The window effect can be achieved with CSS positioning.
As for one complete resource for this specific task, you'd be pretty lucky to find anything. But have a look at the smaller, individual parts and you'll find plenty of resources. Have a look around for information on modal windows, adding elements to the DOM, and AJAX processing.

Categories

Resources