Currently I am using an click element to open a popup box to share some content on the social network
The code i used is :
$('#qq').attr("onclick", "window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + encodeURIComponent(location.href) + "&title=" + encodeURIComponent(shareDes) + "&pics=" + imgStr + "', 'QQshare','toolbar=0,status=0,width=800,height=500');");
Which generate a box , and in that box there is an textarea
<textarea class="view_summary" id="summary" ><%=escHTML(summary)%></textarea>
How to clear the element inside it? I simply add $('.view_summary').empty(); after the create box code, which does not work. Thanks
If the new window has the same domain as the page opening it then try
$('#qq').on("click", function(){
var win = window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + encodeURIComponent(location.href) + "&title=" + encodeURIComponent(shareDes) + "&pics=" + imgStr + "', 'QQshare','toolbar=0,status=0,width=800,height=500');
win.onload = function(){
$('#summary', win.document).val('');
}
});
Demo: Plunker
i'm not sure on this, but you might want to try $('#summary').empty();
Related
I am using lazy load plugin (jquery.lazyload.js) and I try to get the image size that it loads.
So in the display part I have:
echo '<img #img id="img-' . $i . '" name="' . $filename . '" class="lazy" data-original="'.$image.'" />';
Java Script:
<script type="text/javascript">
displaysize(img) {
console.log(img.clientWidth, img.clientHeight);
}
</script>
<script src="js/rectangle3.class.js"></script>
HTML:
<div id="imgsize">
<p id='imgsize-debug'></p>
<button id='map-download-btn' onclick='displaysize();'>Image size:</button>
<div id='imagesize'></div>
</div>
The image display is ok but when I add displaysize(img) function to the script and button, the page keep loading. I will need to get image size for calculation in my java script file,
document.getElementById("rectRecord-" + this.rectPointer).innerHTML =
"Rectangle " + (this.rectPointer + 1) + " ("
+ this.startX + ", "
+ this.startY + ", "
+ this.endX + ", "
+ this.endY + ")"
need to change to:
document.getElementById("rectRecord-" + this.rectPointer).innerHTML =
"Rectangle " + (this.rectPointer + 1) + " ("
+ (this.startX)/width + ", "
+ (this.startY)/height + ", "
+ (this.endX-this.startX)/width+" , "
+ (this.endY-this.startY)/height +""
As I said in the comments, you need to pass the image to the function in order to fetch the width/height. In this example you can click the image to get the size.
In order to use a button you would need to use a selector to target the right image you want the dimensions of.
function displaysize(img) {
console.log(img.clientWidth, img.clientHeight);
}
$(function() {
$("img.lazy").lazyload();
$(document).on('click', '.lazy', function() {
displaysize($(this)[0]);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery_lazyload/1.9.7/jquery.lazyload.js"></script>
<img class="lazy" data-original="http://appelsiini.net/img/bmw_m1_hood.jpg" />
Where is the display size button relative to your lazy loaded image?
Does each lazy load image have a display size button or is there only one lazy loaded image?
Your problem is that your displaysize method which uses a parameter called img but you do not pass any parameter when you call the function on click.
So you need to pass something to that display size method which will point it to the correct image.
Of your image is like this relative to your button:
<img id="lazyLoadedImage" />
<div id="imgsize">
<p id='imgsize-debug'></p>
<button id='map-download-btn' onclick='displaysize("lazyLoadedImage");'>Image size:</button>
<div id='imagesize'></div>
</div>
displaysize(imgID) {
console.log(document.getElementById(imgID).width + ","+ document.getElementById(imgID).height);
}
If you do not have a static set up like this depending on the questions i asked at the beginning here you will have to adjust this code. However whatever the case you will be able to do this by passing an actual reference of the image you would like to inspect to your display image size method.
According to lazy loading plugin site you need to set image dimensions before loading the image:
PRO TIP! You must set image dimensions either as width and height attributes or in CSS. Otherwise plugin might not work properly.
I see you are using PHP, so you can try to set width and height as advised in this answer.
You can also add an id to your images to make the javascript call from the button easier.
Finnaly I managed to find the width and height of the image since it is parent of the rectangular I created inside. So in the javascript file I will use:
var options = {
width: $('#' + rectangles[rectPointer].rectangleDiv.id).parent().width() + 1,
height: $('#' + rectangles[rectPointer].rectangleDiv.id).parent().height() - 3
};
Then width and height get from:
(options.width ||rectangles[rectPointer].startX) + " "
options.height ||rectangles[rectPointer].startY
then for my calculation:
Rectangle.prototype.updatePosition = function (data, options) {
this.startX = data.newStartX;
this.startY = data.newStartY;
this.endY = parseFloat(this.startY) + parseFloat(this.rectangleDiv.style.height);
this.endX = parseFloat(this.startX) + parseFloat(this.rectangleDiv.style.width);
console.log("END: "
+ parseFloat(this.startY) + parseFloat(this.rectangleDiv.style.height) + " - " + parseFloat(this.startX) + parseFloat(this.rectangleDiv.style.width));
document.getElementById("rectRecord-" + this.rectPointer).innerHTML =
"Rectangle " + (this.rectPointer + 1) + " ("
+ (options.width || this.startX) + ", "
+ (options.height || this.startY) + ", "
+ (this.startX)/(options.width || this.startX) + ", "
+ (this.startY)/(options.height || this.startY) + ")"
;
Thanks all for your help ! I have credited up points for all but couldn't accept as answer since it doesn't really be used to solve my issue.
I would like to prettify this URL in the output, how can i do that?
var msg = beasts[loc.beast_id] + "! Left "+dateFormat(timeToDespawn, "MM:ss")+" Link " + " https://www.google.com/maps/dir/Current+Location/"+loc.latitude+","+loc.longitude+" ";
The word "Link" should directly link to this:
https://www.google.com/maps/dir/Current+Location/"+loc.latitude+","+loc.longitude+"
is this possible, and how?
Thanks in advance!
Assuming you want to output to HTML, you would create your link like this:
var msg = "<a href='https://www.google.com/maps/dir/Current+Location/" + String(loc.latitude) + "," + String(loc.longitude) + "'>Link</a>";
You would use this to output it to your HTML page:
$('#foo').html(msg);
Working jsFiddle.
I have created Jquery tabs and embedded a JSP page on the parent page. I have called on window resize events on both pages. But the inner page function does not get invoked.
For the inner page I have an SVG element which needs to be resized every time the window is resized.
sLinkPageToJunction = '<%=base1%>' + "/InnerTabbedPage.jsp?IntersectionName=" + strIntersectionName + "&FrameName=" + strFrameName + "&ip=" + '<%=ServerIP %>' + "&port=" + '<%=ServerPORT %>' + "&InterCorridorName=" + svgfilename;
if (document.getElementById("JnLive" + strIntersectionName) == null) {
//var nextTab = $('#tabs li').size()+1;
Tabcount = $('#tabs li').size();
// create the tab
$('<li>' + strIntersectionName + ' <button class="close closeTab" align="right" "type="button">x</button></li>').appendTo('#tabs');
// create the tab content
$('<div class="tab-pane" id="tab' + strIntersectionName + '"> <div id="JnLive' + strIntersectionName + '" class="col-sm-6" style="margin-top: 1%"> </div>').appendTo('.tab-content');
var heightvalue = $(window).height();
var widthvalue = $(window).width()
//alert("---->"+heightvalue+"---->"+widthvalue);
var url = "<object id=obj'" + strIntersectionName + "' data='" + sLinkPageToJunction + "' height='" + heightvalue + "' width='" + widthvalue + "'></object>";
$("#JnLive" + strIntersectionName).html(url);
// make the new tab active
$('#tabs a:last').tab('show');
OpenedTabbedJunctionNames[Tabcount - 1] = strIntersectionName;
OpenedTabbedJunctionFrameNames[Tabcount - 1] = strFrameName;
registerCloseEvent();
}
So it creates a new tab if it does not already exist.
Now my on windowresize event on the inner page is
window.addEventListener('resize', changeframesizeJN) ;
on the outer page it is
window.addEventListener('resize', changeframesize) ;
But when I resize the window with the tab selected changeframesizeJN is not invoked.
How can I do that?
P.S: I dont know if I have put the information that is required for the question to be answered. The fact is I am not sure how to ask this question.
You give your panel a fixed width and height from what I can tell from your code. You should change the CSS of your inner page to resize with it's parent.
Alternatively you could call the inner page function on the resize of its outer parent as well as its own. Since its on the same domain you won't have any problem doing this:
window.addEventListener('resize', function() {
changeframesize();
window.frames['yourIframeName'].changeframesizeJN();
});
Just make sure you give your inner window a name so you can select it. Or use it's index but I would recommend using a name to keep it readable:
window.frames[0].changeframesizeJN();
Try adding the resize onto the object tag, like:
var url = "<object id=obj'" + strIntersectionName + "' onresize='changeframesizeJN()' data='" + sLinkPageToJunction + "' height='" + heightvalue + "' width='" + widthvalue + "'></object>";
If that works then you can bind it to the object, the same as your window, except with the object element instead.
objectElement.addEventListener('resize', changeframesizeJN) ;
I've following code:
var txt=$("textarea#" + params.field + "-quill").val();
$("#" + params.field + "-quill").hide();
//console.log(context);
$("#" + params.field).show();
$("#" + params.field).val(txt);
I just want to copy the text from first textarea
$("textarea#" + params.field + "-quill")
then hide() it and show() an other textarea
$("#" + params.field).show();
Now I want to paste copied text in this textarea. The textarea get show() and get hide() accordingly but text not get paste?
Please help.
Dont hide textarea before copying it. so better first you copy , Show and then you hide it .
var txt=$("textarea#" + params.field + "-quill").val();
$("#" + params.field).val(txt);
$("#" + params.field).show();
$("#" + params.field + "-quill").hide();
I need help with a little script ...
when i append content and drigger create tho content is loaded...
but then when i use $('#set').empty(); for the second time the content is loaded but no JQM style is added (just plain text)
i have read about this problem but i dont find any solution ... i guess that $('#set').collapsibleset('refresh');as it should... any idea ?
thanks
var content ="<div data-role='collapsible' id='set" + i + "'><h3>Sectionit " + i + "</h3><p>I\'m collapsible number ' + i + '</p></div>";
$('#set').append(content).trigger("create");
$('#set').collapsibleset('refresh');
Instead of
var content ="<div data-role='collapsible' id='set" + i + "'><h3>Sectionit " + i + "</h3><p>I\'m collapsible number ' + i + '</p></div>";
$('#set').append(content).trigger("create");
$('#set').collapsibleset('refresh');
try
$('#set').empty();
var content ="<div data-role='collapsible' id='set" + i + "'><h3>Sectionit " + i + "</h3><p>I\'m collapsible number ' + i + '</p></div>";
$('#set').append(content);
$('#set').collapsibleset().trigger("create");
In this way you only call trigger('create') once after all content has been added.
Here is a DEMO